#!/usr/bin/perl
#ssdelete.cgi  delete snapshot volume
require './lvm-lib.pl';
&ReadParse();
my $svname = $in{'sv'};
my ($err_msg, $s, $sv, @svinfo);
@svinfo = get_snapshot_info();

my $found = 0;
foreach $s (@svinfo) {
	if ($s->{'sv'} eq $svname) {
		$found = 1;
		$sv = $s;
		last;
	}
}

if (!$found) {
	$err_msg = $text{'err_lvnofound'};
	goto ERROR_OUT;
}
$sv->{'sv'} =~ /^(\/dev\/vg\d+\/)$sv->{'svname'}$/;
$lv = $1.$sv->{'originlv'};
#$err_msg = $sv->{'sv'}.$lv;
#goto ERROR_OUT;
if($lv->{'status_m'}){
	`umount $lv->{'lvpath'}`;
	if($?){
		$err_msg = $text{'err_lvbusy'};
		goto ERROR_OUT;
	}
}
if($lv->{'status_i'}){
	$err_msg = $text{'err_iscsi_lv_nodelete'};
	goto ERROR_OUT;
}
my $rc = remove_sv($sv);
if(!$rc){
	#delete_voltab();
	&redirect("snapshot.cgi?lv=$lv");
}
elsif($rc eq 1280){
	$err_msg = $rc.$text{'err_lvdelete'}; #iscsi?
	goto ERROR_OUT;
}
else{
	$err_msg = $rc.$text{'err_lvdelete'};
	goto ERROR_OUT;
}
return;
ERROR_OUT:
&error_setup($text{'crt_err_title'});
&error($err_msg);
